package com.sun.decrypt;


import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Base64Test {
    private static final String UTF8 = StandardCharsets.UTF_8.name();
    //jdk的base64实现
    @Test
    public void test1() throws UnsupportedEncodingException {
        String str = "就是玩";
        String encode = Base64.getEncoder().encodeToString(str.getBytes(UTF8));
        System.out.println("base64加密串 encode = " + encode);
        byte[] decode = Base64.getDecoder().decode(encode.getBytes(UTF8));
        String string = new String(decode, UTF8);
        System.out.println("解密串" + string);

    }
    //apache的base64实现
    @Test
    public void test2() throws UnsupportedEncodingException {
        String str = "就是玩";
        String encode = org.apache.commons.codec.binary.Base64.encodeBase64String(str.getBytes(UTF8));
        System.out.println("base64加密串 encode = " + encode);
        byte[] decode = org.apache.commons.codec.binary.Base64.decodeBase64(encode.getBytes(UTF8));
        String string = new String(decode, UTF8);
        System.out.println("解密串" + string);
    }
}
